CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT( LIBHIDAPI )

INCLUDE_DIRECTORIES( "${LIBHIDAPI_SOURCE_DIR}/hidapi" )

# build-setup for linux...

IF( UNIX )

    # ==================================================
    # check if building for linux, if so configure it...
    # ==================================================
    IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
    
        FIND_PACKAGE( LibUSB1 REQUIRED )
        INCLUDE_DIRECTORIES( ${LIBUSB1_INCLUDE_DIR} )
        
        ADD_DEFINITIONS( -O3 )

        SET( SOURCES
             hidapi/hidapi.h
             linux/hid-libusb.c )
        ADD_LIBRARY( hidapi STATIC ${SOURCES} )
        TARGET_LINK_LIBRARIES( hidapi ${LIBUSB1_LIBRARY} )
        
    ELSE()
        MESSAGE( ERROR "Operating System currently not supported! Sorry." )
    ENDIF()

ENDIF( UNIX)

IF( WIN32 )

    # ==================================================
    # configure for windows
    # ==================================================

    SET( CMAKE_C_STANDARD_LIBRARIES 
	 ${CMAKE_C_STANDARD_LIBRARIES}
         setupapi.lib )

    SET( SOURCES
         hidapi/hidapi.h
         windows/hid.c )

    ADD_LIBRARY( hidapi SHARED ${SOURCES} )

ENDIF( WIN32 )

# mark install-target (only hidapi.dll) for windows.
#IF( WIN32 )
#	FIND_FILE( HIDAPI_DLL_FILE hidapi.dll
#	           PATHS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}" )
#	MESSAGE( "HIDAPI_DLL_FILE: ${HIDAPI_DLL_FILE}" )
#
#    INSTALL( FILES hidapi.dll 
#             DESTINATION "c:/Program\ Files\ (x86)/PappSDR/" )
#ENDIF()
